package com.tsingteng.cosfun.ui.message.comment.videocomment;

import android.util.Log;

import com.tsingteng.cosfun.bean.AddVideoCommentResultBean;
import com.tsingteng.cosfun.bean.BaseDataBean;
import com.tsingteng.cosfun.bean.CommBean;
import com.tsingteng.cosfun.bean.MessageVideoCommentBean;
import com.tsingteng.cosfun.bean.VideoCommentBean;
import com.tsingteng.cosfun.bean.VideoPriseResultBean;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * @我。赞我。评论我页面点击展示视频评论页P层
 * 常胜
 * 2018.8.23
 * */
public class VideoCommentPresenter implements  VideoCommentContract.IVideoCommentPresenter{

    private VideoCommentContract.IVideoCommentView view;
    private VideoCommentModel videoCommentModel;

    public VideoCommentPresenter(VideoCommentFragment videoCommentFragment){
        videoCommentModel = new VideoCommentModel();
        view = videoCommentFragment;
    }
    @Override
    public void getVideoCommentList(int page, int id,String commonId) {
        videoCommentModel.getVideoCommentListResponse(page,id, commonId,new Callback<MessageVideoCommentBean>() {
            @Override
            public void onResponse(Call<MessageVideoCommentBean> call, Response<MessageVideoCommentBean> response) {
                if(response.body()!= null){
                    view.showVideoCommentListResult(response.body());
                }
            }

            @Override
            public void onFailure(Call<MessageVideoCommentBean> call, Throwable t) {

            }
        });
    }


    @Override
    public void getMyVideoComment(String workId, String commentId, String pointerUserId, String commentMsg, int isTop) {
        videoCommentModel.getMyVideoCommentResponse(workId,commentId+"",pointerUserId+"",commentMsg,isTop, new Callback<AddVideoCommentResultBean>() {
            @Override
            public void onResponse(Call<AddVideoCommentResultBean> call, Response<AddVideoCommentResultBean> response) {
                if(response.body() != null){
                    view.showMyVideoCommentResult(response.body());
                }
            }

            @Override
            public void onFailure(Call<AddVideoCommentResultBean> call, Throwable t) {
                Log.e("onFailure",t.getMessage());
            }
        });
    }

    @Override
    public void getPriseCount(String workId, int type) {
        videoCommentModel.getPriseResponse(workId,type, new Callback<BaseDataBean<CommBean>>() {
            @Override
            public void onResponse(Call<BaseDataBean<CommBean>> call, Response<BaseDataBean<CommBean>> response) {
                view.showPriseCount(response.body().getData().getStatus());
            }

            @Override
            public void onFailure(Call<BaseDataBean<CommBean>> call, Throwable t) {
                view.showFail("网络错误!");
            }
        });
    }

    @Override
    public void commDel(String commid) {
        videoCommentModel.commDel(commid, new Callback<BaseDataBean<String>>() {
            @Override
            public void onResponse(Call<BaseDataBean<String>> call, Response<BaseDataBean<String>> response) {

            }

            @Override
            public void onFailure(Call<BaseDataBean<String>> call, Throwable t) {

            }
        });
    }
}
